package com.tepth.maintenancesystem.view;

import android.content.Context;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.tepth.maintenancesystem.R;
import com.tepth.maintenancesystem.SysApplication;
import com.tepth.maintenancesystem.bean.Contents;
import com.tepth.maintenancesystem.bean.LoginObj;
import com.tepth.maintenancesystem.bean.MaintainRefer;
import com.tepth.maintenancesystem.untils.Untils;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

public class MaintainWorkCompletedDetailsActivity extends AppCompatActivity {

    @BindView(R.id.tv_work_details_title)
    TextView tv_work_details_title;

    @BindView(R.id.tv_work_details_content_name)
    TextView tv_work_details_content_name;

    @BindView(R.id.tv_work_details_content_desc)
    TextView tv_work_details_content_desc;

    @BindView(R.id.tv_work_details_status)
    TextView tv_work_details_status;

    @BindView(R.id.tv_work_details_name_status)
    TextView tv_work_details_name_status;

    @BindView(R.id.tv_work_details_remark)
    TextView tv_work_details_remark;

    @BindView(R.id.linear_status)
    LinearLayout linear_status;

    private Contents obj;
    private Context context;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_maintain_work_completed_details);
        SysApplication.getInstance().addActivity(this);
        context=this;
        ButterKnife.bind(this);
        Bundle bundle=getIntent().getBundleExtra("bundle");
        obj = bundle.getParcelable("contents");
        String vehicleName=bundle.getString("vehicleName");
        tv_work_details_title.setText(vehicleName+" 作业详情");
        tv_work_details_content_name.setText(bundle.getString("workName"));
        tv_work_details_content_desc.setText(obj.getContentDesc());
        if(obj.getValueTypeCode().equals("select")){
            linear_status.setVisibility(View.VISIBLE);
            tv_work_details_status.setText(getStatus(obj.getValueTypeDetail(),obj.getValue()));
            if(obj.getRemark().equals("")||obj.getRemark().equals("null")){
                tv_work_details_remark.setText("无");
            }else{
                tv_work_details_remark.setText(obj.getRemark());
            }
        }else if(obj.getValueTypeCode().equals("numeric")){
            linear_status.setVisibility(View.VISIBLE);
            tv_work_details_name_status.setText("数值");
            tv_work_details_status.setText(obj.getValue());
            if(obj.getRemark().equals("")||obj.getRemark().equals("null")){
                tv_work_details_remark.setText("无");
            }else{
                tv_work_details_remark.setText(obj.getRemark());
            }
        }else{
            linear_status.setVisibility(View.GONE);
            findViewById(R.id.view_status).setVisibility(View.GONE);
            if(obj.getValue().equals("")||obj.getValue().equals("null")){
                tv_work_details_remark.setText("无");
            }else{
                tv_work_details_remark.setText(obj.getValue());
            }
        }

    }

    @OnClick(R.id.rl_work_details_back)
    public void click(View view){
        switch (view.getId()){
            case R.id.rl_work_details_back:
                this.finish();
                break;
        }
    }

    private String getStatus(String valueTypeDetail,String value){
        List<MaintainRefer> refers= Untils.getMaintianRefer(context);
        String valueStr="";
        for (int i=0;i<refers.size();i++){
            if(refers.get(i).getSelectType().equals(valueTypeDetail)){
                List<MaintainRefer.Selection> selection=refers.get(i).getSelections();
                for (int j=0;j<selection.size();j++){
                    if(selection.get(j).getCode().equals(value)){
                        valueStr=selection.get(j).getName();
                    }
                }
            }
        }
        return valueStr;
    }
}
